
#include "stdafx.h"
#include "MyFont.h"

CFont g_font;
int g_nLineWidth = 5;
void GetMyFont(CFont* ptf)
{
	int nFontSize = GetScreenDPIFontSize();
	LOGFONT lf;
	ptf->GetLogFont(&lf);
	g_font.CreatePointFont(nFontSize, lf.lfFaceName);
}
void SetFontVal(CDC* pDC, UINT nCtlColor)
{
	switch (nCtlColor)
	{
	case CTLCOLOR_DLG:
		pDC->SelectObject(&g_font);
		break;
	case CTLCOLOR_STATIC:
		pDC->SelectObject(&g_font);
		break;
	case CTLCOLOR_EDIT:
		pDC->SelectObject(&g_font);
		break;
	case CTLCOLOR_MSGBOX:
		pDC->SelectObject(&g_font);
		break;
	case CTLCOLOR_LISTBOX:
		pDC->SelectObject(&g_font);
		break;
	case CTLCOLOR_BTN:
		pDC->SelectObject(&g_font);
		break;
	case CTLCOLOR_SCROLLBAR:
		pDC->SelectObject(&g_font);
		break;
	}
}

void SetFontVal2(CDC* pDC)
{
	pDC->SelectObject(&g_font);
}

int GetScreenDPIFontSize()
{
	HDC desktopDc = GetDC(NULL);
	int dpi = GetDeviceCaps(desktopDc, LOGPIXELSX);
	int nFontSize = 85;
	switch (dpi) {
	case 96:
		nFontSize = 85;
		g_nLineWidth = 1;
		break;
	case 120:
		nFontSize = 65;
		g_nLineWidth = 9;
		break;
	case 144:
		nFontSize = 55;
		g_nLineWidth = 15;
		break;
	case 192:
		nFontSize = 45;
		g_nLineWidth = 20;
		break;
	default:
		break;
	}
	return nFontSize;
}